@function strip-unit($num) {
    @return $num / ($num * 0 + 1);
}

@function rgba-to-hex($color, $background: #fff) {
    @if $color and alpha($color) != 1 {
        $percent: alpha($color) * 100%;
        $opaque: opacify($color, 1);

        @return mix($opaque, $background, $percent);
    } @else {
        @return $color;
    }
}
@function yiq-value($color) {
    @if $color == transparent {
        @return $body-color;
    } @else if alpha($color) != 1 {
        $color: rgba-to-hex($color);
    }

    $r: red($color);
    $g: green($color);
    $b: blue($color);

    @return (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
}
// 颜色对比
@function yiq($color) {
    $yiq: yiq-value($color);

    @if ($yiq >= 160) {
        @return rgba-to-hex(rgba($color, 0.4), #000);
    } @else {
        @return #fff;
    }
}
@function get-nav-colors(
    $bg,
    $active-color: null,
    $inactive-color: null,
    $border: null
) {
    $bg: rgba-to-hex($bg);
    $active-color: rgba-to-hex($active-color);
    $active-color: if($active-color, $active-color, yiq($bg));
    $yiq-percent: yiq-value($bg) / 255;
    $yiq-percent-inverted: 1 - $yiq-percent;

    $opacity: if(
        $active-color == #fff,
        0.6 + (0.4 * $yiq-percent),
        0.6 + (0.4 * (1 - $yiq-percent))
    );

    $color: if(
        $inactive-color,
        rgba-to-hex($inactive-color, $bg),
        rgba-to-hex(
            rgba(
                $active-color,
                if($yiq-percent < 0.25, $opacity - 0.15, $opacity)
            ),
            $bg
        )
    );
    $disabled-color: rgba-to-hex(rgba($color, 0.6), $bg);
    $muted-color: rgba-to-hex(rgba($color, 0.75), $bg);
    $border: if(
        $border,
        $border,
        if(
            $yiq-percent > 0.75,
            rgba($active-color, $opacity / 8),
            if(
                $yiq-percent < 0.25,
                rgba($active-color, 0.06),
                rgba($active-color, 0.15)
            )
        )
    );

    @return (
        opacity: $opacity,
        yiq-percent: $yiq-percent,
        yiq-percent-inverted: $yiq-percent-inverted,
        bg: $bg,
        color: $color,
        active-color: $active-color,
        disabled-color: $disabled-color,
        muted-color: $muted-color,
        border: $border
    );
}
